package java05;

import java.util.*;
import java.util.Map.Entry;

public class Java54 {

	public static void main(String[] args) {
		Map<Integer,String> eveline = new TreeMap<Integer,String>();
		Map<String,List> map = new TreeMap<String,List>();
        Scanner in = new Scanner(System.in);
        Integer n = 0;
        while(in.hasNextLine()){
            String line= in.nextLine();
            
            if(line.equals("!!!!!"))
                break;
            
            else{
            	n++;
            	eveline.put(n, line);
        		String[] str =  line.split(" ");
            	List<String> letter = new ArrayList<String>();
                for (int i = 0; i < str.length; i++) {
                	
    				if(!str[i].equals("")){
    					List<Integer> arr = new ArrayList<Integer>();
    					if(!map.containsKey(str[i])){
    						
    						arr.add(n);
    		            	map.put(str[i], arr);
    		            }
    					else{
    						
    						arr = map.get(str[i]);
    						if(!arr.contains(n))
    						arr.add(n);
    						map.put(str[i], arr);
    					}
                	}
    			}
            }
        }
        for (Entry<String,List> entry : map.entrySet()) {
        	System.out.println(entry.getKey()+"="+entry.getValue());
		}
		
        while(in.hasNextLine()){

        	String line = in.nextLine();
        	List search = Arrays.asList(line.split(" "));
        	List<Integer> sea = new ArrayList<Integer>();
    		for (Entry<Integer, String> entry : eveline.entrySet()) {
    			List letter = Arrays.asList(entry.getValue().split(" "));
    			if(search.isEmpty()) break;
    			if(letter.containsAll(search)){
    				sea.add(entry.getKey());
    			}
        	}
			if(!sea.isEmpty()){
        		System.out.println(sea);
	        	for (Integer integer : sea) {
	        		System.out.println("line "+integer+":"+eveline.get(integer));
	        	}
        	}
        	else
        		System.out.println("found 0 results");
        }
	}
}
/*
public class Java54 {

	public static void main(String[] args) {
		Map<Integer,String> eveline = new HashMap<Integer,String>();
		Map<String,List<Map<Integer,String>>> map = new HashMap<String,List<Map<Integer,String>>>();
        Scanner in = new Scanner(System.in);
        Integer n = 0;
        while(in.hasNextLine()){
            String line= in.nextLine();
            
            if(line.equals("!!!!!"))
                break;
            
            else{
            	n++;
            	eveline.put(n, line);
        		String[] str =  line.split(" ");
            	List<String> letter = new ArrayList<String>();
                for (int i = 0; i < str.length; i++) {
                	
    				if(!str[i].equals("")){
    					List<Map<Integer,String>> arr = new ArrayList<Map<Integer,String>>();
    					if(!map.containsKey(str[i])){
    						Map<Integer,String> mm = new HashMap<Integer,String>();
    						mm.put(n, line);
    						arr.add(mm);
    		            	map.put(str[i], arr);
    		            }
    					else{
    						arr = map.get(str[i]);
    						Map<Integer,String> mm = new HashMap<Integer,String>();
    						mm.put(n, line);
    						arr.add(mm);
    						map.put(str[i], arr);
    					}
                	}
    			}
            }
        }
        
        List<Map.Entry<String, List<Map<Integer,String>>>> list =
                new LinkedList<Map.Entry<String, List<Map<Integer,String>>>>( map.entrySet() );
            Collections.sort(list, new Comparator<Map.Entry<String, List<Map<Integer,String>>>>()
            {
                public int compare( Map.Entry<String, List<Map<Integer,String>>> o1, Map.Entry<String, List<Map<Integer,String>>> o2 )
                {
                    return (o1.getKey()).compareTo( o2.getKey() );
                }
            } );
            
            for (Entry<String, List<Map<Integer,String>>> entry : list) {
            	List<Integer> word = new ArrayList<Integer>();
	            for (Map m : entry.getValue()) {  
	                Iterator<Map.Entry<Integer, String>> it = m.entrySet().iterator();  
	                while (it.hasNext()) {  
	                    Map.Entry<Integer, String> ele = it.next();  
	                    word.add(ele.getKey());
	                }
	            }
	            System.out.println(entry.getKey()+"="+word);
            }
        while(in.hasNextLine()){

        	String line = in.nextLine();
        	List search = Arrays.asList(line.split(" "));
        	List<Integer> sea = new ArrayList<Integer>();
    		for (Entry<Integer, String> entry : eveline.entrySet()) {
    			List letter = Arrays.asList(entry.getValue().split(" "));
    			if(search.isEmpty()) break;
    			if(letter.containsAll(search)){
    				sea.add(entry.getKey());
    			}
        	}
			if(!sea.isEmpty()){
        		System.out.println(sea);
	        	for (Integer integer : sea) {
	        		System.out.println("line "+integer+":"+eveline.get(integer));
	        	}
        	}
        	else
        		System.out.println("found 0 results");
        }
	}
}
*/
